import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


import '../../AppConfig/Config.dart';
import '../../AppConfig/RouteAct.dart';
import '../../http/api.dart';
import '../../l10n/messages.dart';
import 'ChangNewPhoneNumber.dart';

class VerifyPhoneUserID extends StatefulWidget {
  const VerifyPhoneUserID({super.key});

  @override
  State<VerifyPhoneUserID> createState() => _VerifyPhoneUserIDState();
}

class _VerifyPhoneUserIDState extends State<VerifyPhoneUserID> {
  String name="";
  String IDNum="";
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance?.addPostFrameCallback((_) {
      // 在页面加载后调用 showDialog
      _showDialog();
    });
  }

  void _showDialog() {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return BrnDialog(
          titleText: '收集使用个人敏感信息提示',
          messageText:'我们将收集您提交的【身份证】信息，用于身份信息核验；如果您不同意该项授权，我们将不会获取您提交的个人信息，并且当前功能将无法正常使用',
          actionsWidget: [
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
                Navigator.of(context).pop();
              },
              child: Text("不同意",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
            ),
            TextButton(
              onPressed: () {
                Navigator.of(context).pop(); // 关闭对话框
              },
              child: Text("同意",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
            ),
          ],
        );
      },
    );
  }


  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    var messages = AppLocalizations.of(context)!;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor:Colors.white,
        centerTitle: true,
        title: Text("修改手机号",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
      ),
      body: ListView(children: [
        Container(
          margin: EdgeInsets.only(top: 8.h,left: 10.w,right: 10.w),
          padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 15.h,bottom: 15.h),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(10)),
          ),
          child: Column(
            children: [
              Row(
                children: [
                  Text("*",style: TextStyle(color: MyColors.themeColor),),
                  Text("姓名",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                  SizedBox(width: 20.w,),
                  Container(
                    width: screenSize.width-120.w,
                    height: 35.h,
                    decoration: BoxDecoration(
                      color: MyColors.backgreyColor,
                      borderRadius: BorderRadius.all(Radius.circular(10)),
                    ),
                    child:  TextField(
                      decoration: InputDecoration(
                        hintText: '必填，请输入',
                        hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
                        filled: true,
                        fillColor: MyColors.backgreyColor,
                        border: InputBorder.none,
                        alignLabelWithHint: true,
                      ),
                      keyboardType: TextInputType.number,
                      textAlign: TextAlign.left,
                      style: TextStyle(color: Colors.black),

                      onChanged: (value) {
                        setState(() {
                          name=value;
                        });
                      },
                    ),
                  ),
                ],
              ),
              SizedBox(height: 15.h,),
              Row(
                children: [
                  Text("*",style: TextStyle(color: MyColors.themeColor),),
                  Text("身份证",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                  SizedBox(width: 6.w,),
                  Container(
                    width: screenSize.width-120.w,
                    height: 35.h,
                    decoration: BoxDecoration(
                      color: MyColors.backgreyColor,
                      borderRadius: BorderRadius.all(Radius.circular(10)),
                    ),
                    child:  TextField(
                      decoration: InputDecoration(
                        hintText: '必填，请输入',
                        hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
                        filled: true,
                        fillColor: MyColors.backgreyColor,
                        border: InputBorder.none,
                        alignLabelWithHint: true,
                      ),
                      keyboardType: TextInputType.number,
                      textAlign: TextAlign.left,
                      style: TextStyle(color: Colors.black),

                      onChanged: (value) {
                        setState(() {
                          IDNum=value;
                        });
                      },
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: 8.h,left: 10.w),
          child:Text("*姓名身份证号需要和原手机号注册账号保持一致。",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
        ),
        SizedBox(height: 50.h,),
        Container(margin: EdgeInsets.only(left: 15.w,right: 15.w),
          child:    BrnSmallMainButton(
            title: '提交',
            bgColor: MyColors.themeColor,
            fontSize: 16.sp,
            radius: 30,
            onTap: () {
              ApiManager.postData(
                context,
                'api/auth/shipper/user/checkIdentity',
                {
                  "name":name,
                  "idNum":IDNum,
                },
                    (responseData) async {
                  BrnToast.show("提交成功", context, duration: BrnDuration.short,);
                  Navigator.push( context, FadeRoute(page:ChangNewPhoneNumber()));
                },
              );


            },
          ),
        ),
      ],
      ),
    );
  }
}
